
import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:shop/pages/login/api.dart';

import '../../datas/homeListData.dart';
import '../../utils/md5.dart';
import '../../utils/token_utils.dart';

class LoginViewPage extends StatefulWidget{
  final String? redirect;
  const LoginViewPage({super.key, this.redirect});
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
   return _LoginViewPageState();
  }
}

class _LoginViewPageState extends State<LoginViewPage> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(title: Text("登陆"),),
      body: SafeArea(child: Center(child:InkWell(
        onTap:  ()async{
         Map<String,dynamic> loginData = {};
         loginData["mobile"] = "19939962786";
         loginData["password"] = MD5Utils.encrypt("123");
         LoginViewModel viewModel = LoginViewModel();
         final HomeListItemData? userList =await viewModel.login(loginData);
         //模拟登陆成功 返回数据就成功 返回首页
         TokenUtils.saveToken(userList.toString());
         context.replace("/");
        },
        child: Text("登陆"),
      ),)),
    );
  }
}